package qe.spider.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Data
public class Plate {
    private String code;
    private String name;
    private BigDecimal v1;
    private BigDecimal ZhangFu;
    private BigDecimal ZhangSu;
    private BigDecimal v4;
    private BigDecimal ZhuLiJingE;  //主力净额（主力金额）
    private BigDecimal ZhuLiBuy;
    private BigDecimal ZhuLiSell;
    private BigDecimal v8;
    private BigDecimal ZongLiuTongZhi;
    private BigDecimal QuJianZhangFu;
    private String BanKuaiDianShu;
    private Date grabTime;

    private BigDecimal zhulijingliang;  //主力净量
    private Integer zhangTingCnt;   //涨停数
    private Integer zhangCnt;   //涨家数
    private Integer dieCnt;   //跌家数
    private String category;  //板块分类（精选、概念、行业、地区等）

    private Boolean isUp = false;//是否上榜
    private Date upTime;//上榜时间

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Plate plate = (Plate) o;
        if (null != code && !code.isEmpty()) return code.equals(plate.code);
        else if (null != name && !name.isEmpty()) return name.equals(plate.name);
        else return super.equals(o);
    }

    @Override
    public int hashCode() {
        if (null != code && !code.isEmpty()) return Objects.hash(code);
        else if (null != name && !name.isEmpty()) return Objects.hash(name);
        else return super.hashCode();
    }

    public Plate update(Plate np) {
        if (np == null || !np.name.equals(this.name)) return this;
//        if (np.grabTime == null || np.grabTime.before(this.grabTime)) return this;
        if (np.grabTime != null && this.grabTime != null && np.grabTime.after(this.grabTime))
            this.grabTime = np.grabTime;
        if (np.ZhangFu != null) this.ZhangFu = np.ZhangFu;
        if (np.ZhangSu != null) this.ZhangSu = np.ZhangSu;
        if (np.ZhuLiJingE != null) this.ZhuLiJingE = np.ZhuLiJingE;
        if (np.ZhuLiBuy != null) this.ZhuLiBuy = np.ZhuLiBuy;
        if (np.ZhuLiSell != null) this.ZhuLiSell = np.ZhuLiSell;
        if (np.ZongLiuTongZhi != null) this.ZongLiuTongZhi = np.ZongLiuTongZhi;
        if (np.QuJianZhangFu != null) this.QuJianZhangFu = np.QuJianZhangFu;
        if (np.BanKuaiDianShu != null) this.BanKuaiDianShu = np.BanKuaiDianShu;
        if (np.zhulijingliang != null) this.zhulijingliang = np.zhulijingliang;
        if (np.zhangTingCnt != null) this.zhangTingCnt = np.zhangTingCnt;
        if (np.zhangCnt != null) this.zhangCnt = np.zhangCnt;
        if (np.dieCnt != null) this.dieCnt = np.dieCnt;
        if (np.category != null) this.category = np.category;
        return this;
    }

    //上榜
    public Plate upTop() {
        if (isUp) return this;  //已上榜的不处理
        isUp = true;
        upTime = new Date();
        return this;
    }

    //下榜
    public Plate downTop() {
        isUp = false;
        upTime = null;
        return this;
    }
}
